﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using SiteECSWeb;
using System.Web.Services;
using System.Web.Script.Services;

public partial class DefaultMain : PageBase
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HyperNewsLinkMore.NavigateUrl = Helper.NavURLDateParamsVirtualName(DateTime.Now.Month, DateTime.Now.Year,
            Globals.Settings.VirtualNamesInfo.NewsArchive);
        }
        //Master.CompanyInfo;
        //Page.Title = "You are good in some thing";
        //Page.Header.Title = "ajhdfjksdkjfhjkjhx";
        //Response.Write("isla");
        //DisplayAlert("Heloo man");
        //Response.Write(Request.Browser.Browser);
        //Response.Write(AppDomain.CurrentDomain.BaseDirectory);
        
    }
   
    #region WebServiceMethod
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    //[GenerateScriptType(typeof(OfficeInfo))]
    public static List<FairsInfo> GetFarisItems(int pageindex, int pagesize)
    {
        FairsBLL frAPI = new FairsBLL();

        EcsSiteDS.FairsDataTable frtable = frAPI.GetAllFairsData();
        List<FairsInfo> FrInfo = new List<FairsInfo>();
        foreach (EcsSiteDS.FairsRow frRow in frtable)
        {
            FrInfo.Add(new
                FairsInfo
                (frRow.Fair_id, frRow.Fair_nm, frRow.Fair_strtdate, frRow.Fair_enddate,
                frRow.Fair_website, frRow.CountryNmAr,frRow.CountryNmEn, frRow.WCompNmEn,
                frRow.IsFair_ImagePathNull() ? string.Empty : frRow.Fair_ImagePath));
        }
        return FrInfo.GetRange((pageindex - 1 * pagesize), pagesize);
    }
    #endregion

    protected string MyEval(object ss)
    {
        return Helper.NavURLParamsIntVirtualName(ss, Globals.Settings.VirtualNamesInfo.FairsDetails);
    }

    protected string ReduceString(object str)
    {
        string mystr = string.Empty;
        if (!string.IsNullOrEmpty(str.ToString()))
        {
            if (str.ToString().Length > 120)
            {
                mystr = str.ToString().Substring(0, 120) + " .....";
            }
            else
            {
                mystr = str.ToString();
            }
        }
        return mystr;
    }
    protected void ReptTenders_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            if (e.Item.ItemIndex == 0)
            {

                EcsSiteDS.TendersRow tenderrow = (EcsSiteDS.TendersRow)
                    ((System.Data.DataRowView)e.Item.DataItem).Row;

                Repeater subTenders = e.Item.FindControl("rptSubTenders") as Repeater;
                TenderBLL tenderAPI = new TenderBLL();
                EcsSiteDS.TendersDataTable tenderTable = 
                    tenderAPI.GetTendersByTenderID(tenderrow.Tend_id);
                subTenders.DataSource = tenderTable;
                subTenders.DataBind();

            }
        }
    }
    protected void ReptTradAffectSub_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            if (e.Item.ItemIndex == 0)
            {

                EcsSiteDS.TradAffectSubRow TradAffectSubrow = (EcsSiteDS.TradAffectSubRow)
                    ((System.Data.DataRowView)e.Item.DataItem).Row;

                Repeater subTradAffect = e.Item.FindControl("rptSubTradAffect") as Repeater;
                TradAffectSubBLL TradAffectAPI = new TradAffectSubBLL();
                EcsSiteDS.TradAffectSubDataTable TradAffectTable =
                    TradAffectAPI.GetTradAffectSubByTradAffectSubID(TradAffectSubrow.TrdaffSub_Id);
                subTradAffect.DataSource = TradAffectTable;
                subTradAffect.DataBind();

            }
        }
    }
    protected void ReptNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            if (e.Item.ItemIndex == 0)
            {
                EcsSiteDS.NewsRow newsrow = (EcsSiteDS.NewsRow)
                    ((System.Data.DataRowView)e.Item.DataItem).Row;

                Repeater subNews = e.Item.FindControl("rptSubNews") as Repeater;
                NewsBLL newsAPI = new NewsBLL();
                EcsSiteDS.NewsDataTable newstable = newsAPI.GetNewsDataByNewsID(newsrow.News_id);
                subNews.DataSource = newstable;
                subNews.DataBind();

            }
        }
    }
    protected void ReptExportOpp_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            if (e.Item.ItemIndex == 0)
            {
                EcsSiteDS.ExpOpprtintyRow exOpprow = (EcsSiteDS.ExpOpprtintyRow)
                    ((System.Data.DataRowView)e.Item.DataItem).Row;

                Repeater subExportOpp = e.Item.FindControl("rptSubExportOpp") as Repeater;
                ExpOppBLL ExpOppAPI = new ExpOppBLL();
                EcsSiteDS.ExpOpprtintyDataTable exOpptable =
                    ExpOppAPI.GetExportOppByExpOppID(exOpprow.Ex_oprtid);
                subExportOpp.DataSource = exOpptable;
                subExportOpp.DataBind();
            }
        }
    }
}
